package cn.com.ntr.jhclient.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
import cn.com.ntr.jhclient.R;
import cn.com.ntr.jhclient.model.ResumeLang;

public class LangListAdapter extends EnhancedAdapter<ResumeLang> {
	public static Map<Integer, String> map;
	public LangListAdapter(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		map=new HashMap<Integer, String>();
	}
	public void addAll(List<ResumeLang> list){
		this.dataList=list;
		notifyDataSetChanged();
	}
	@Override
	protected void bindView(View paramView, Context paramContext, final int position) {
		// TODO Auto-generated method stub
		final ResumeLang lang=getItem(position);
		ViewHolder holder=(ViewHolder)paramView.getTag();	
		holder.tvLang.setTextSize(18);
		holder.tvMaster.setTextSize(16);
		holder.tvMaster.setTextColor(mContext.getResources().getColor(R.color.gray_1));
		holder.tvLang.setText(lang.getLangName());
		holder.tvMaster.setText(lang.getMaster());
		holder.chk.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				// TODO Auto-generated method stub
				dataList.get(position).setChecked(isChecked);
				if (isChecked) {
					map.put(position, lang.getLid());
				} else {
					map.remove(position);
				}
			}
		});
		holder.chk.setChecked(dataList.get(position).isChecked());
	
	}

	@Override
	protected View newView(Context context, int i, ViewGroup viewgroup) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.lang_item, null);
		ViewHolder holder = new ViewHolder();
		holder.tvLang=(TextView)view.findViewById(R.id.tv_info);
		holder.tvMaster=(TextView)view.findViewById(R.id.tv_count);
		holder.chk=(CheckBox)view.findViewById(R.id.delete);
		view.setTag(holder);
		return view;
	}

	private class ViewHolder {
		TextView tvLang,tvMaster;
		CheckBox chk;
	}
}
